package com.leete.observer;

import java.util.Observable;
import java.util.Observer;

/**
 * @author liqiang
 * @version 1.0
 * @description:
 * @date 2023/5/6 17:41
 */
public class Subject {

    public static void main(String[] args) {
        MyObservable observable = new MyObservable();

        Observer observer = new Observer() {
            public void update(Observable o, Object arg) {
                System.out.println("观察者" + this.getClass().getName() + "收到通知--" + arg);
            }
        };

        Observer observer1 = new Observer() {
            public void update(Observable o, Object arg) {
                System.out.println("观察者" + this.getClass().getName() + "收到通知--" + arg);
            }
        };

        observable.addObserver(observer);
        observable.addObserver(observer1);

        System.out.println(observable.countObservers());
        // 标记为已改变 才会发出通知
        observable.setChanged();
        observable.notifyObservers("大家好");

    }





}
